﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Classes.virals {

    public class Viral {

        private var m_viralType:String;
        private var m_originTimestamp:Number;
        private var m_timesPosted:uint;
        private var m_recipients:Object;

        public function Viral(_arg1:String, _arg2:uint, _arg3:Number, _arg4:Object=null){
            this.m_viralType = _arg1;
            this.m_originTimestamp = _arg3;
            this.m_timesPosted = _arg2;
            if (!_arg4){
                this.m_recipients = {};
            } else {
                this.m_recipients = _arg4;
            };
        }
        private static function checkIfRewardIsPresent(_arg1:XMLList, _arg2:String):Boolean{
            var _local4:XML;
            var _local3:int;
            while (_local3 < _arg1.reward.length()) {
                _local4 = _arg1.reward[_local3];
                if (_local4.@type == _arg2){
                    return (true);
                };
                _local3++;
            };
            return (false);
        }
        public static function getViralHelperRewardText(_arg1:String):String{
            var _local2:XML = Global.gameSettings.getViralXMLByName(_arg1);
            if (_local2.reward == null){
                return (ZLoc.t("Dialogs", "Share"));
            };
            if (_local2.reward.helperRewards == null){
                return (ZLoc.t("Dialogs", "Share"));
            };
            if (checkIfRewardIsPresent(_local2.reward.helperRewards, "reward_cash")){
                return (ZLoc.t("Dialogs", "ShareCash"));
            };
            if (checkIfRewardIsPresent(_local2.reward.helperRewards, "reward_energy")){
                return (ZLoc.t("Dialogs", "ShareEnergy"));
            };
            if (checkIfRewardIsPresent(_local2.reward.helperRewards, "reward_xp")){
                return (ZLoc.t("Dialogs", "ShareExperience"));
            };
            if (checkIfRewardIsPresent(_local2.reward.helperRewards, "reward_coins")){
                return (ZLoc.t("Dialogs", "ShareCoins"));
            };
            if (checkIfRewardIsPresent(_local2.reward.helperRewards, "reward_goods")){
                return (ZLoc.t("Dialogs", "ShareGoods"));
            };
            return (ZLoc.t("Dialogs", "Share"));
        }

        public function addPost(_arg1:String):void{
            this.m_timesPosted++;
            var _local2:XML = Global.gameSettings.getViralXMLByName(this.m_viralType);
            if (((_local2.limitOnePerRecipient) && ((String(_local2.limitOnePerRecipient) == "true")))){
                this.m_recipients[("i" + _arg1)] = new Date().getTime();
            };
        }
        public function get timesPosted():uint{
            return (this.m_timesPosted);
        }
        public function getType():String{
            return (this.m_viralType);
        }
        public function timeToUnlock():int{
            var _local1:Number = (GlobalEngine.serverTime / 1000);
            var _local2:Number = (_local1 - this.m_originTimestamp);
            var _local3:XML = Global.gameSettings.getViralXMLByName(this.m_viralType);
            var _local4:int = (Number((_local3.timeTillReset * 3600)) - _local2);
            return (Math.max(0, _local4));
        }
        public function hasReset():Boolean{
            var _local1:Number = (GlobalEngine.serverTime / 1000);
            var _local2:Number = (_local1 - this.m_originTimestamp);
            var _local3:XML = Global.gameSettings.getViralXMLByName(this.m_viralType);
            return ((_local2 >= Number((_local3.timeTillReset * 3600))));
        }
        public function hasHitPostLimit(_arg1:String):Boolean{
            var _local2:XML = Global.gameSettings.getViralXMLByName(this.m_viralType);
            if (((_local2.limitOnePerRecipient) && ((String(_local2.limitOnePerRecipient) == "true")))){
                if (this.m_recipients[("i" + _arg1)]){
                    return (true);
                };
            };
            if (_local2.maxPosts.length() > 0){
                return ((this.m_timesPosted >= uint(_local2.maxPosts)));
            };
            return (false);
        }

    }
}//package Classes.virals 
